//
//  ZZCSetPayPwordTweController.m
//  ZZC-Finance
//
//  Created by a on 2017/8/20.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCSetPayPwordTweController.h"
#import "ZZCMeController.h"
#import "ZZCShoppingController.h"
#import "ZZCOwnPropertyController.h"
@interface ZZCSetPayPwordTweController ()
@property (weak, nonatomic) IBOutlet UITextField *PwdFld;

@end

@implementation ZZCSetPayPwordTweController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"设置支付密码";
}


//确认设置密码
- (IBAction)testClick {
    if (_PwdFld.text == nil) {
        return;
    }
    NSString *token = ZZCNSUserDefaults(@"token");
    NSDictionary *dict = @{@"code":_code,
                           @"pay_password":_PwdFld.text,
                           @"token":token};
    NSLog(@"%@",token);
    NSString *sign = [ZZCRequest getSignWithDict:dict];
    sign = [NSString md5:[sign lowercaseString]];
    NSDictionary *param = @{
                            @"timestamp":[NSString timeStr],@"sign":sign,
                            @"code":_code,
                            @"pay_password":_PwdFld.text,
                            @"token":token
                            };
    [[ZZCRequest sharedNetworkTools] POST:ZZCURL_API_SET_PASSWORD parameters:param finished:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (error) {
            ZZCLog(@"失败-%@",error);
            [SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@",error]];
        }else {
            NSLog(@"%@",dict);
            [SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@",responseObject[@"msg"]]];
            //            self.codeTextFld.text = [responseObject[@"data"][@"code"] stringValue];
            if ([responseObject[@"code"] isEqual:@(200)]) {
                for (UIViewController *controller in self.navigationController.viewControllers) {
                    if ([controller isKindOfClass:[ZZCMeController class]]||
                        [controller isKindOfClass:[ZZCShoppingController class]]||
                        [controller isKindOfClass:[ZZCOwnPropertyController class]]) {
                        [self.navigationController popToViewController:controller animated:YES];
                        //这里可以做回到登录界面的一些数据操作
                    }
                }

            }
        }
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
